<template>
	<u-swiper :height="height" :list="arr" indicator indicatorMode="line" circular radius=0 bindload='fetchList'
		imgMode="aspectFill" @click="onClick">
	</u-swiper>
</template>

<script>
	import {
		mapGetters
	} from "vuex";
	import {
		bannerListApi
	} from "@/api/project.js";
	export default {
		props: {
			height: {
				type: [String, Number],
				default: 200
			},
			whether: {
				type: Boolean,
				default: true
			},
			info: [String, Object],
			project_minid:{
				type:String
			}
		},
		data() {
			return {
				picArr: [
					require('../../src/imgs/test3.png'),
					require('../../src/imgs/test2.jpg'),
					require('../../src/imgs/test4.jpg'),
				],
				Arr: [
					require('../../src/imgs/test5.jpg'),
				],
				arr: [],
			}
		},
		computed: {
			...mapGetters({
				curProject: "system/getCurProject",
			}),
		},
		methods: {
			async fetchList() {
				this.arr = [],
					uni.showLoading({
						title: "加载中...",
					});
				const {
					data
				} = await bannerListApi({
					project_id: this.project_minid
				});
				if (this.info.is_access !== 1) {
					this.arr.push(this.Arr[0])
				}
				if (data.data.length >= 1) {
				 let arr = data.data.map(item => item.file_path ? item.file_path.replace(/\\/g, '/') : '');
					arr.forEach(item => {
						this.arr.push(item);
					})
				} else {
					this.picArr.forEach(item => [
						this.arr.push(item)
					])
				}
				uni.hideLoading();
			},
			onClick(idx) {
				if(this.whether){
					if (this.info.is_access !== 1) {
						if (idx === 0) {
							this.$emit('toPlace');
							return
						}
					}
				}
			
				//预览图片
				uni.previewImage({
					current: idx,
					urls: this.arr,
					indicator: 'number',
					loop: true,
				})
			},
		},
		// mounted() {
		// 	this.arr=[],
		// 	this.fetchList();
		// },
		onShow() {
			this.fetchList();
		}
	}
</script>

<style>
</style>
